<template>
	<view>
		<scroll-view class="nav" scroll-x="true">
			<view class="nav_box">
				<block v-for="(item, index) in navList" :key="index">
					<view class="nav_item" @tap="navClick(index)" :class="[navIndex == index?'name_avtive':'']">{{ item.name }}</view>
				</block>
			</view>
		</scroll-view>
		<!-- 内容 -->
		<list :list='list' :status="status" :contentText="contentText" :stateType="stateType" :addType="addType"></list>
	</view>
</template>

<script>
	import util from '@/common/util.js';
	import list from '@/components/artlist/artlist';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			list,
			uniLoadMore
		},
		data() {
			return {
				navList: [{
					name: '全部'
				}, {
					name: '审核中'
				}, {
					name: '已通过'
				}, {
					name: '违规'
				}],
				navIndex: 0,
				list: [],
				reload: true,
				page: 1,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				},
				stateType: '', // 0为默认抖教文章
				addType: '', //附加条件: 0+0为首页抖教推荐  0+1为智囊团  1+3为家文化&孩子-目标、成长、才艺  2+2为育儿经&育儿经-我的  3+4为我的智囊团
			}
		},
		onPullDownRefresh() {
			this.reload = true;
			this.page = 1;
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getList();
			}, 500);
		},
		onNavigationBarButtonTap() {
			var url = '';
			if(this.addType) {
				url = '/pages/articleModule/article-release?stateType='+this.stateType+'&addType='+this.addType
			} else {
				url = '/pages/articleModule/article-release?stateType='+this.stateType
			}
			uni.navigateTo({
				url: url
			})
		},
		onShow() {
			this.reload = true;
			this.page = 1;
			this.getList();
		},
		onLoad(e) {
			this.stateType = e.stateType;
			this.addType = e.addType;
			if(this.stateType == 3) {
				uni.setNavigationBarTitle({
					title: '我的智囊团'
				})
			}
		},
		methods: {
			/* 获取文章列表 */
			getList() {
				var data = {
					is_user: 1,
					page: this.page,
					pagesize: 7
				}
				if (this.navIndex != 0) {
					data.is_check = this.navIndex;
				}
				var url = '';
				if(this.stateType == 0) {
					url = 'user/article.Lists/articleList';
				} else if(this.stateType == 3) {
					url = 'user/wisdom.Lists/articleList';
				}
				this.$zapi.apiPost(url, data).then(res => {
					if (res.data.code == 200) {
						var list = res.data.data.data;
						for (var i = 0; i < list.length; i++) {
							list[i].time = util.getBriefTime(list[i].creat_time);
							if(list[i].subhead_creat_time) {
								list[i].ftime = util.getBriefTime(list[i].subhead_creat_time);
							}
						}
						this.list = this.reload ? list : this.list.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						if (this.reload) {
							this.list = [];
						} else {
							this.status = 'noMore';
						}
					}
				})
			},
			/* 类型切换 */
			navClick(index) {
				this.navIndex = index;
				this.reload = true;
				this.page = 1;
				this.getList()
			}
		}
	}
</script>

<style>
	page {
		background: #FAFAFA;
	}

	/* 顶部 */
	.nav {
		width: 100%;
		height: 90upx;
		color: #999999;
		background-color: #FFFFFF;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
	}

	.nav_box {
		display: flex;
		white-space: nowrap;
	}

	.nav_item {
		width: 25%;
		display: flex;
		align-items: center;
		height: 90upx;
		line-height: 80upx;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		font-size: 32upx;
	}

	.name_avtive {
		color: #FF9900;
	}

	.name_avtive:after {
		content: '';
		line-height: 90upx;
		background: #FF9900;
		height: 4upx;
		width: 28upx;
		font-weight: bold;
	}
</style>
